﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.App.Applications.Aquaculture;
using Traceability.App.Applications.DeepProcess;
using Traceability.App.Applications.Slaughter;
using Traceability.App.Applications.Traceability;
using Traceability.App.DTO;
using Traceability.Domain;
using Traceability.ErrorCode;

namespace Traceability.App.Controllers
{
    /// <summary>
    /// 溯源基本信息控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TrancController : ControllerBase
    {
        private readonly IMediator mediator;

        public TrancController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加溯源基本信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddTraceability(TraceabilityAddCommand request) 
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 获取商品信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<T_Goods>>> GetGoodsList() 
        {
            GoodsQueryCommand request = new GoodsQueryCommand();
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取基本信息列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<APIPaging<TraceabilityListDto>>> GetTraceabilityList([FromQuery] TraceabilityQueryCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 编辑/删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> TraceabilityEadit(TraceabilityEaditCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<int>> RangeDel(string json) 
        {
            TraceabilityRemoveCommand request = new TraceabilityRemoveCommand();
            request.Json = json;
            return await mediator.Send(request);

        }
        /// <summary>
        /// 获取基本信息详情
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<TraceabilityListDto>> GetTraceabilityBasic([FromQuery]TraceabilityDetailCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 添加养殖信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddAquaculture(AquacultureAddCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取养殖信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<T_Aquaculture>> GetAquaculture([FromQuery]AquacultureQueryCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取免疫信息列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<HealthDto>>> GetHealthList(string batch) 
        {
            HealthQueryCommand request = new HealthQueryCommand();
            request.Batch = batch;
            return mediator.Send(request);
        }
        /// <summary>
        /// 添加免疫信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddHealth(HealthAddCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 编辑屠宰信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> EaditSlaughter(SlaughterEaditCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 屠宰信息的反填
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<T_Slaughter>> GetSlaughterData([FromQuery]SlaughterQueryCommand request) 
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 深加信息的编辑
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> EaditDeepProcess(DeepProcessEaditCommand request) 
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 获取深加工信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<T_DeepProcess>> GetProcess([FromQuery]DeepProcessQueryCommand request) 
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 设置供货商信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> EditSupplier(VendorEditCommand request) 
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取供应商信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<T_Supplier>> GetVendor([FromQuery]VendorQueryCommand request) 
        {
            return mediator.Send(request);
        }
    }
}
